const commonUrl = "http://127.0.0.1:8080"; //公共路径

const HTTPS = 'http://127.0.0.1:8080'
const imgurl = 'http://127.0.0.1:8080'
const httpRequest = require('./http/request.js');
import {
	getToken,
	setToken,
	removeToken
} from '@/libs/auth';
import {
	login
} from '@/api/user';


// post请求封装
async function myRequest(url, data, method = "GET" || "POST" || "PUT" || "DELETE") {

	let header = {
		"content-type": "application/json"
	}
	if (!getToken()) {
		await login()
	}
	header.Authorization = getToken()
	let requestRes = await httpRequest.request(url, data, method, header)
	// console.log("requestRes", requestRes)
	if (requestRes.code === 101) {
		// 登录过期
		await login()
		header.Authorization = getToken()
		requestRes = await httpRequest.request(url, data, method, header)
	}
	// console.log("requestRes2", requestRes)
	return requestRes

}


module.exports = {
	myRequest: myRequest,
	commonUrl: commonUrl,
	HTTPS: HTTPS,
	imgurl: imgurl
};